package com.candy.th7;

public class Child extends Thread {
    private Kitchen kitchen;

    //属性：体力值，默认为0，即没有吃饭的状态
    private int hp=0;
    //健康值，吃饱后健康值和体力值相等
    private int health;

    public Child(String name, Kitchen kitchen,int health) {
        super(name);
        this.kitchen = kitchen;
        this.health = health;
    }

    public void eat() {
        try {
            this.kitchen.do_eat();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        //当体力值小于健康值，说明他没有吃饱，可以一直进行吃饭的行为，直到吃饱了为止
        while (this.hp<this.health) {
            this.eat();
        }
        System.out.println(this.getName()+"吃饱了，谢谢妈妈~~~~~~~~~~~~~~~~~~~~~");
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }
}
